package com.ws.haungjia.controller;

import com.ws.haungjia.Bean.Lunbo;
import com.ws.haungjia.Bean.luxian;
import com.ws.haungjia.Service.LvxingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/lunbo")
public class LunboController {

    @Autowired
    private LvxingService lvxingService;

    @RequestMapping("/chaxun")
    public String chaxun(Model model){
        List<Lunbo> lunbos = lvxingService.luncha();
        model.addAttribute("lunbos",lunbos);
        return "WEB-INF/houtai/lunbo/list";
    }

    @RequestMapping("/zengjia")
    public String zengjia(int packageID){
        luxian lunhui = lvxingService.lunhui(packageID);
        int lunzeng = lvxingService.lunzeng(lunhui);
        if (lunzeng > 0) {
            return "redirect:/lunbo/chaxun";
        }else{
            return "WEB-INF/houtai/lunbo/add";
        }
    }

    @RequestMapping("/shan")
    public String shan(int id){
        int shan = lvxingService.lunshan(id);
        if (shan > 0) {
            return "redirect:/lunbo/chaxun";
        }else {
            return "redirect:/lunbo/chaxun";
        }
    }



    @RequestMapping("/tiozhuan")
    public String tiao()
    {
        return "redirect:/lunbo/chaxun";
    }
}
